package com.ruoyi.pingjiao.utils;

import com.ruoyi.pingjiao.domain.CourseassessName;
import com.ruoyi.pingjiao.domain.Teacher;
import com.ruoyi.pingjiao.service.ITeacherService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

public class CourseassessTree {


    public static   List<CourseassessName> makeTree(List<CourseassessName>courseassessNames,Long pid){
        List<CourseassessName>courseassessNameList=new ArrayList<>();
        Optional.ofNullable(courseassessNames).orElse(new ArrayList<>()).stream()
                .filter(item->item!=null&& Objects.equals(item.getParentId(), pid)).forEach(item->{
                    CourseassessName courseassessName=new CourseassessName();
//                    Teacher teacher = teacherService.selectTeacherByTeacherId(item.getTeacherId());
                    BeanUtils.copyProperties(item,courseassessName);
//                    courseassessName.setTeacherName(teacher.getRealName());
                    List<CourseassessName> courseassessNameList1 = makeTree(courseassessNames, item.getId());
                    courseassessName.setChildren(courseassessNameList1);
                    courseassessNameList.add(courseassessName);
                });
        return courseassessNameList;
    }


}
